/**
 * created by 小卷毛, 2021-09-10
 * Copyright (c) 2021, 416143467@qq.com All Rights Reserved.
 * #                   *********                            #
 * #                  ************                          #
 * #                  *************                         #
 * #                 **  ***********                        #
 * #                ***  ****** *****                       #
 * #                *** *******   ****                      #
 * #               ***  ********** ****                     #
 * #              ****  *********** ****                    #
 * #            *****   ***********  *****                  #
 * #           ******   *** ********   *****                #
 * #           *****   ***   ********   ******              #
 * #          ******   ***  ***********   ******            #
 * #         ******   **** **************  ******           #
 * #        *******  ********************* *******          #
 * #        *******  ******************************         #
 * #       *******  ****** ***************** *******        #
 * #       *******  ****** ****** *********   ******        #
 * #       *******    **  ******   ******     ******        #
 * #       *******        ******    *****     *****         #
 * #        ******        *****     *****     ****          #
 * #         *****        ****      *****     ***           #
 * #          *****       ***        ***      *             #
 * #            **       ****        ****                   #
 */
package com.xinnuo.account

import android.accounts.Account
import android.app.Service
import android.content.*
import android.os.Bundle
import android.os.IBinder
import android.util.Log


/**
 * 描 述：
 *      清单配置：
 *      <!-- 账户同步服务 -->
 *      <service
 *         android:name=".account.AccountSyncService"
 *         android:enabled="true"
 *         android:exported="true">
 *           <intent-filter>
 *              <action android:name="android.content.SyncAdapter" />
 *           </intent-filter>

 *           <meta-data
 *              android:name="android.content.SyncAdapter"
 *              android:resource="@xml/sync_adapter" />
 *      </service>
 *
 * 作 者：小卷毛  2021-09-10 13:57
 * 修改描述：
 * 修 改 人：
 * 修改版本：
 */
class AccountSyncService : Service() {

    // 账户同步 IBinder 对象
    private lateinit var mThreadSyncAdapter: ThreadSyncAdapter

    override fun onBind(intent: Intent?): IBinder? = mThreadSyncAdapter.syncAdapterBinder

    override fun onCreate() {
        super.onCreate()

        mThreadSyncAdapter = ThreadSyncAdapter(this, true)
    }

    inner class ThreadSyncAdapter : AbstractThreadedSyncAdapter {

        constructor(context: Context, autoInitialize: Boolean) : this(
            context,
            autoInitialize,
            false
        )

        constructor(context: Context, autoInitialize: Boolean, allowParallelSyncs: Boolean) : super(
            context,
            autoInitialize,
            allowParallelSyncs
        )

        override fun onPerformSync(
            account: Account?,
            extras: Bundle?,
            authority: String?,
            provider: ContentProviderClient?,
            syncResult: SyncResult?
        ) {
            // 账户同步操作
            // 与数据库 , 服务器同步操作 , 这里只是为了应用进程拉活 , 不实现具体的逻辑
            Log.i("AccountSyncService", "账户同步拉活激活")
        }

    }

}